<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Promotional extends My_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model("Promotional_model","promotional");
    }

    /**
     *------------------------------------------------------------------------------------------------------------------
     * @title：首页新闻接口
     * @action：/news/index
     * @method：GET
     * @author:：KevinBai
     *------------------------------------------------------------------------------------------------------------------
     */
    public function index(){
        $this->isArrays = true;
        $params['per_page'] = $this->queryData['per_page'];
        $params['region'] = $this->queryData['region'];
        $validate = new Validate([
            'per_page' => 'require|number',
        ]);
        if (!$validate->check($params)) {
            $this->errorCode = 50003;
            $this->errorMessage = $validate->getError();
            $this->createApi();
            exit;
        }
        $limit  = $this->config->item('limit');
        $jobsList = $this->promotional->getPromotionalList($params,$params['per_page'], $limit," id,name,content,publishtime");
        foreach ($jobsList as $key => $value) {
            $jobsList[$key]['content'] = cutstr(strip_tags($value['content']),30);
            $jobsList[$key]['publishtime'] = humanDate($value['publishtime']);
        }
        $this->createApi($jobsList); exit();
    }


	
    /**
     *------------------------------------------------------------------------------------------------------------------
     * @title：新闻详情
     * @action：/news/newsDetail
     * @method：POST
     * @author:：柏凯
     * @date：2015-11-13
     *------------------------------------------------------------------------------------------------------------------
     */
    public function detail(){
        $params['id'] = $this->queryData['id'];;
        $validate = new Validate([
            'id' => 'require|number',
        ]);
        if (!$validate->check($params)) {
            $this->errorCode = 50003;
            $this->errorMessage = $validate->getError();
            $this->createApi();
            exit;
        }
        $data = array();
        $jobsDetail = $this->promotional->getPromotionalDetail($params['id'],"id,name,content,publishtime");
        if($jobsDetail){
            $jobsDetail['publishtime'] = humanDate($jobsDetail['publishtime']); 
            $jobsDetail['content'] = $jobsDetail['content'];
            $this->createApi($jobsDetail);
        }else{
            $this->errorCode = 50008;
            $this->createApi();exit;
        }
    }
}

/* End of file region.php */
/* Location: ./application/controllers/region.php */
